package com.jzo2o.customer.controller.open;

import com.jzo2o.customer.model.domain.ServeProvider;
import com.jzo2o.customer.model.dto.request.InstitutionRegisterReqDTO;
import com.jzo2o.customer.service.IServeProviderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author robin
 * @date 25.6.28 17:25
 */
@RestController("openServeProviderRegisterController")
@RequestMapping("/open/serve-provider")
@Api(tags = "服务端或者机构端-客户注册相关接口")
@RequiredArgsConstructor
public class ServeProviderRegisterController {
    private final IServeProviderService serveProviderService;
    private final PasswordEncoder passwordEncoder;

    @PostMapping("/institution/register")
    @ApiOperation("服务人员/机构人员注册接口")
    public ServeProvider register(@Valid @RequestBody InstitutionRegisterReqDTO institutionRegisterReqDTO) {
        String encodePass = passwordEncoder.encode(institutionRegisterReqDTO.getPassword());
        return serveProviderService.add(institutionRegisterReqDTO.getPhone(), institutionRegisterReqDTO.getType(), encodePass, institutionRegisterReqDTO.getVerifyCode());
    }
}
